package com.yanqu.road.server.cmd.tradewar.cross;

import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.TradeWarModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TRADE_WAR_BUY_BUFF, desc = "跨服商战购买buff")
public class CrossTradeWarBuyBuffCmd extends AbstractCommand {

	private int activityId;

	private int times;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarBuyBuffReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarBuyBuffReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		times = reqMsg.getBuyTimes();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(TradeWarModule.class).buyCrossBattleBuff(activityId, times);
	}

	@Override
	public void sendData(GamePlayer player) {
		CrossTradeWarProto.CrossTradeWarBuyBuffRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarBuyBuffRespMsg.newBuilder();
		respMsg.setRet(ret);
		respMsg.setActivityId(activityId);
		respMsg.setTotalBuyTimes(player.getModule(TradeWarModule.class).getCrossUserTradeWarBattle().getBuyBuffTimes());
		player.sendPacket(Protocol.U_CROSS_TRADE_WAR_BUY_BUFF, respMsg);
	}
}
